//
//  MinTabBarController.m
//  OnionHome
//
//  Created by fengjie on 2019/9/13.
//  Copyright © 2019 FengJie. All rights reserved.
//

#import "MinTabBarController.h"
#import "HomeBasseViewController.h"
#import "MeViewController.h"


@interface MinTabBarController ()

@end

@implementation MinTabBarController

+(void)initialize{
    // 通过appearance统一设置所有UITabBarItem的文字属性
    NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
    attrs[NSFontAttributeName] = SYSTEMFONT(12);
    attrs[NSForegroundColorAttributeName] = UIColorFromRGB(0x454F44);
    
    NSMutableDictionary *selectedAttrs = [NSMutableDictionary dictionary];
    selectedAttrs[NSFontAttributeName] = attrs[NSFontAttributeName];
    selectedAttrs[NSForegroundColorAttributeName] = UIColorFromRGB(0x009966);
    
    UITabBarItem *item = [UITabBarItem appearance];
    [item setTitleTextAttributes:attrs forState:UIControlStateNormal];
    [item setTitleTextAttributes:selectedAttrs forState:UIControlStateSelected];
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self tabBarViews];
    //设置为NO用来解决iOS12后，页面跳转回一级页面的时候tabbar跳动的bug
    [UITabBar appearance].translucent = NO;
    
//    self.selectedIndex = 1;
}
-(void)tabBarViews{
    [self setupChildVc:[[HomeBasseViewController alloc]init] title:@"首页" image:@"home" selectedImage:@"home-dj"];
    [self setupChildVc:[[MeViewController alloc]init] title:@"我的" image:@"me" selectedImage:@"me-dj"];
}
/**
 *  初始化子控制器
 */
- (void)setupChildVc:(UIViewController *)vc title:(NSString *)title image:(NSString *)image selectedImage:(NSString *)selectedImage{
    // 设置文字和图片
    vc.navigationItem.title = title;
    vc.tabBarItem.title = title;
    vc.tabBarItem.image = IMAGE_NAMED(image);
    vc.tabBarItem.selectedImage = [UIImage imageNamed:selectedImage];
    // 包装一个导航控制器, 添加导航控制器为tabbarcontroller的子控制器
    BasseNavigationController *nav = [[BasseNavigationController alloc] initWithRootViewController:vc];
    [self addChildViewController:nav];
    
}

@end
